package kr.hkit.powerjava.chapter22.work3.dao;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;

import kr.hkit.powerjava.chapter22.work3.vo.Student;

public class StudentImpl implements ItemDaoInterface<Student> {

	private LinkedList<Student> lkList;

	public StudentImpl(LinkedList<Student> lkList) {
		this.lkList = lkList;
	}

	@Override
	public void addItem(Student item) {
		lkList.add(item);
	}

	@Override
	public void delItem(Student item) {
		lkList.remove(item);
	}

	@Override
	public void updateItem(Student item) {
		if (searchItem(item)) {
			lkList.set(lkList.indexOf(item), item);
		} else {
			System.out.println("수정 실패");
		}
	}

	@Override
	public boolean searchItem(Student item) {
		return lkList.contains(item);
	}

	@Override
	public void prnItems() {
		prnHeader();
		// Collections.sort(arList);
		for (Student s : lkList) {
			System.out.println(s);
		}
		System.out.println();
	}

	private void prnHeader() {
		String str = String.format("%3s\t%5s\t%3s\t%3s\t%3s\t%5s\t%5s", "학번",
				"성명", "국어", "영어", "수학", "총점", "평균");
		System.out.println(str);
		System.out
				.println("------------------------------------------------------");
	}

	public void prnItems(Comparator<Student> comp) {
		Collections.sort(lkList, comp);
		prnItems();
	}

}
